package com.abcdefg.springaopdemo.proxy;

import org.springframework.cglib.proxy.Enhancer;

import java.lang.reflect.Proxy;

public class Main {
    public static void main(String[] args) {
        //静态代理
//        HouseSubject target=new RealHouseSubject();
//        HouseSubject houseSubject=new HouseProxy(target);
//        houseSubject.buyHouse();
//        houseSubject.saleHouse();

        //JDk动态代理
        //动态创建一个代理类
//        HouseSubject target=new RealHouseSubject();
//        HouseSubject houseProxy=(HouseSubject) Proxy.newProxyInstance(target.getClass().getClassLoader(),
//                new Class[]{HouseSubject.class},new JDKInvocation(target));
//        houseProxy.saleHouse();

        //Cglib 动态代理
        HouseSubject target=new RealHouseSubject();
        /**
         * import org.springframework.cglib.proxy.MethodInterceptor;
         * import org.springframework.cglib.proxy.MethodProxy;
         */
        HouseSubject houseProxy = (HouseSubject) Enhancer.create(target.getClass(),new CGlibMethodInterceptor(target));
        houseProxy.saleHouse();
    }
}
